package tw.com.softleader.spring.app;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import tw.com.softleader.spring.service.SpringService;

public class SpringApp {
	
	/** 透過Slf4j API 取得Logger(目前使用log4j) */
	private static final Logger log = LoggerFactory.getLogger(SpringApp.class);
	
	public static void main(String[] args){
		/** 取得 ApplicationContext(與Spring Container溝通的橋樑) 
		 *  傳入參數為想要讀取的Spring定義檔位置，預設根目錄為 src\main\resources\
		 * */
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[]{"spring-service.xml"});
		/**
		 * 透過ApplicationContext取得spring-service.xml中bean id = springService的物件
		 * */
		SpringService springService = (SpringService) applicationContext.getBean("springService");
		
		log.debug("springService.getHello(Chris) = {}", springService.getHello("Chris"));
		log.debug("springService.getAll() = {}", springService.getAll().toString());
	}
}
